package com.mybatis.controller;

import com.mybatis.mapper.DepartMapper;
import com.mybatis.pojo.Depart;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cyt
 * @create 2020-03-16 10:42
 */

@RestController
public class Test {

    @Autowired
    public DepartMapper departMapper;

    @HystrixCommand(fallbackMethod = "hystrix")
    @RequestMapping("/hystrix/{id}")
    public Depart get(@PathVariable("id") Integer id) {
        Depart depart = departMapper.selectByPrimaryKey(id);
        if (depart == null) {
            throw new RuntimeException("null .....");
        }
        return depart;
    }


    public Depart hystrix(@PathVariable("id") Integer id) {
        Depart depart = new Depart();
        depart.setName("这个用户不存在！");
        return depart;
    }

}
